home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Educational / LEE 2.1 / Source / interact.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-06  |  7.3 KB  |  316 lines

  1. #include "defs.h"
  2.  
  3.  
  4. void actInWorldInteractive(organism, numExpelled, startX, startY)
  5.     struct indiv    *organism;
  6.     int                numExpelled, startX, startY;
  7. {
  8.     if (gInteractive) {
  9. #ifdef THINK_C
  10.         if ((organism->worldx == gCurrentZoomCell.h) && (organism->worldy == gCurrentZoomCell.v) && (gCurrentZoomItem == 0) && !((organism->worldx==startX) && (organism->worldy==startY))) {
  11.             gCurrentZoomItem+=numExpelled;
  12.         }
  13.         drawCell(organism->worldx, organism->worldy);
  14. #endif
  15. #ifdef __MWERKS__
  16.         if ((organism->worldx == gCurrentZoomCell.h) && (organism->worldy == gCurrentZoomCell.v) && (gCurrentZoomItem == 0) && !((organism->worldx==startX) && (organism->worldy==startY))) {
  17.             gCurrentZoomItem+=numExpelled;
  18.         }
  19.         drawCell(organism->worldx, organism->worldy);
  20. #endif
  21.  
  22.     }
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29. void    ins_org_Interactive(ip)
  30.     struct indiv    *ip;
  31. {
  32.     if (gInteractive) {
  33. #ifdef THINK_C
  34.         if ((ip->worldx == gCurrentZoomCell.h) && (ip->worldy == gCurrentZoomCell.v))
  35.             gCurrentZoomItem++;
  36.         drawCell(ip->worldx, ip->worldy);
  37. #endif
  38. #ifdef __MWERKS__
  39.         if ((ip->worldx == gCurrentZoomCell.h) && (ip->worldy == gCurrentZoomCell.v))
  40.             gCurrentZoomItem++;
  41.         drawCell(ip->worldx, ip->worldy);
  42. #endif
  43.  
  44.     }
  45. }
  46.  
  47.  
  48.  
  49.  
  50. void    EventsInteractive()
  51. {    
  52. #ifdef THINK_C
  53.     do {
  54.         HandleEvent();
  55.     } while  (gPaused && (!gDone));
  56. #endif
  57. #ifdef __MWERKS__
  58.     do {
  59.         /* SIOUXHandleOneEvent() called by HandleEvent() in macinterface.c */
  60.         HandleEvent();
  61.     } while  (gPaused && (!gDone));
  62. #endif
  63.  
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. void    del_org_Interactive(x, y, itemNum)
  71.     int        x,y,itemNum;
  72. {
  73.     if (gInteractive) {
  74. #ifdef THINK_C
  75.         if ((x == gCurrentZoomCell.h) && (y == gCurrentZoomCell.v))
  76.             if (gCurrentZoomItem>itemNum)
  77.                 gCurrentZoomItem--;
  78.             else if (gCurrentZoomItem==itemNum)
  79.                 gCurrentZoomItem==0;
  80.         drawCell(x, y);
  81. #endif
  82. #ifdef __MWERKS__
  83.         if ((x == gCurrentZoomCell.h) && (y == gCurrentZoomCell.v))
  84.             if (gCurrentZoomItem>itemNum)
  85.                 gCurrentZoomItem--;
  86.             else if (gCurrentZoomItem==itemNum)
  87.                 gCurrentZoomItem==0;
  88.         drawCell(x, y);
  89. #endif
  90.  
  91.     }
  92. }
  93.  
  94.  
  95.  
  96.  
  97. void update_world_Interactive(xpos, ypos)
  98.     int        xpos, ypos;
  99. {
  100.     if (gInteractive) {
  101. #ifdef THINK_C
  102.         if ((xpos == gCurrentZoomCell.h) && (ypos == gCurrentZoomCell.v))
  103.             gCurrentZoomItem++;
  104.         drawCell(xpos, ypos);
  105. #endif
  106. #ifdef __MWERKS__
  107.         if ((xpos == gCurrentZoomCell.h) && (ypos == gCurrentZoomCell.v))
  108.             gCurrentZoomItem++;
  109.         drawCell(xpos, ypos);
  110. #endif
  111.  
  112.     }
  113. }
  114.  
  115.  
  116.  
  117.  
  118. void    updateGenInteractive()
  119. {
  120.     if (gInteractive) {
  121. #ifdef THINK_C
  122.         updateGeneration();
  123. #endif 
  124. #ifdef __MWERKS__
  125.         updateGeneration();
  126. #endif 
  127.  
  128.     }
  129. }
  130.  
  131.  
  132.  
  133. void    InteractiveInit(argc, argv)
  134.     int     *argc;
  135.     char  ***argv;
  136. {
  137. #ifdef THINK_C
  138.         ToolBoxInit();
  139.         MoreMasters();
  140.         MaxApplZone();
  141.         InitMenuBar();
  142.         *argc = ccommand(argv);
  143.         InitWindow();
  144.         gInitDialog = GetNewDialog(INIT_DIALOG, NIL_POINTER, (WindowPtr) -1);
  145.         SetPort(gInitDialog);
  146.         DrawDialog(gInitDialog);
  147.         SetPort(gTheWindow);
  148.                 if ((x_dim > 25)||(y_dim > 25))
  149.                 {
  150.                         /* verbose = 1; */
  151.                         gInteractive = FALSE;
  152.                         printf("\nMacintosh Warning:");
  153.                         printf("\n\tWorld size too large for interactive mode:");
  154.                         printf("\n\tRunning in non-interactive mode...\n");
  155.                 }
  156.                 else
  157.                 {
  158.                         /* verbose = 0; */
  159.                         gInteractive = TRUE;
  160.                 }
  161. #endif
  162. #ifdef __MWERKS__
  163.  
  164.         /* SIOUX settings for console i/o */
  165.         
  166.         SIOUXSettings.initializeTB = FALSE;        
  167.         SIOUXSettings.standalone = TRUE;
  168.         SIOUXSettings.setupmenus = FALSE;
  169.         SIOUXSettings.autocloseonquit = TRUE;
  170.         SIOUXSettings.showstatusline = FALSE;
  171.         SIOUXSettings.asktosaveonclose = TRUE;
  172.         
  173.         ToolBoxInit();
  174.         MoreMasters();
  175.         MaxApplZone();
  176.         InitMenuBar();
  177.         *argc = ccommand(argv);
  178.         InitWindow();
  179.         gInitDialog = GetNewDialog(INIT_DIALOG, NIL_POINTER, (WindowPtr) -1);
  180.         SetPort(gInitDialog);
  181.         DrawDialog(gInitDialog);
  182.         SetPort(gTheWindow);
  183.                 if ((x_dim > 25)||(y_dim > 25))
  184.                 {
  185.                         /* verbose = 1; */
  186.                         gInteractive = FALSE;
  187.                         printf("\nMacintosh Warning:");
  188.                         printf("\n\tWorld size too large for interactive mode:");
  189.                         printf("\n\tRunning in non-interactive mode...\n");
  190.                 }
  191.                 else
  192.                 {
  193.                         /* verbose = 0; */
  194.                         gInteractive = TRUE;
  195.                 }
  196. #endif
  197.  
  198. }
  199.  
  200.  
  201.  
  202.  
  203. void    InteractiveFinalSetUp()
  204. {
  205. #ifdef THINK_C
  206.         DisposDialog(gInitDialog);
  207. #endif
  208. #ifdef __MWERKS__
  209.         DisposDialog(gInitDialog);
  210. #endif
  211.  
  212. }
  213.  
  214.  
  215.  
  216.  
  217. void    moveInteractiveLasso(orgItemNum, isSelected, organism)
  218.     int             orgItemNum;
  219.     boolean            *isSelected;
  220.     struct indiv    *organism;
  221. {
  222.  
  223. #ifdef THINK_C
  224.     Rect        r;
  225.     PenState    thePen;
  226. #endif
  227. #ifdef __MWERKS__
  228.     Rect        r;
  229.     PenState    thePen;
  230. #endif
  231.  
  232.  
  233.  
  234.     if (gInteractive) {
  235. #ifdef THINK_C
  236.         if ((FrontWindow()==gZoomCellWindow) && (gCurrentZoomCell.h == organism->worldx) && (gCurrentZoomCell.v == organism->worldy) && gLassoOn && (gCurrentZoomItem==orgItemNum)) {
  237.             *isSelected = TRUE;
  238.             
  239.             GetPenState(&thePen);
  240.             PenPat(&white /* CW: qd.white */ );
  241.             SetRect(&r, START_X+gCurrentZoomCell.h*SQUARE_SIZE, START_Y+gCurrentZoomCell.v*SQUARE_SIZE, START_X+(gCurrentZoomCell.h+1)*SQUARE_SIZE - GAP_SIZE, START_Y+(gCurrentZoomCell.v+1)*SQUARE_SIZE-GAP_SIZE);
  242.             SetRect(&r, r.left-2, r.top-2,r.right+2, r.bottom+2);
  243.             FrameRect(&r);
  244.             SetPenState(&thePen);
  245.     
  246.             gCurrentZoomCell.h = -1;
  247.             gCurrentZoomCell.v = -1;
  248.         }
  249. #endif
  250. #ifdef __MWERKS__
  251.         if ((FrontWindow()==gZoomCellWindow) && (gCurrentZoomCell.h == organism->worldx) && (gCurrentZoomCell.v == organism->worldy) && gLassoOn && (gCurrentZoomItem==orgItemNum)) {
  252.             *isSelected = TRUE;
  253.             
  254.             GetPenState(&thePen);
  255.             PenPat(&qd.white);
  256.             SetRect(&r, START_X+gCurrentZoomCell.h*SQUARE_SIZE, START_Y+gCurrentZoomCell.v*SQUARE_SIZE, START_X+(gCurrentZoomCell.h+1)*SQUARE_SIZE - GAP_SIZE, START_Y+(gCurrentZoomCell.v+1)*SQUARE_SIZE-GAP_SIZE);
  257.             SetRect(&r, r.left-2, r.top-2,r.right+2, r.bottom+2);
  258.             FrameRect(&r);
  259.             SetPenState(&thePen);
  260.     
  261.             gCurrentZoomCell.h = -1;
  262.             gCurrentZoomCell.v = -1;
  263.         }
  264. #endif
  265.  
  266.     }
  267. }
  268.  
  269.  
  270. void    moveInteractDrawSelectFrame(isSelected, new_pos)
  271.     boolean        isSelected;
  272.     position    new_pos;
  273. {
  274.  
  275. #ifdef THINK_C
  276.     Rect        r;
  277.     PenState    thePen;
  278. #endif
  279. #ifdef __MWERKS__
  280.     Rect        r;
  281.     PenState    thePen;
  282. #endif
  283.  
  284.  
  285.  
  286.     if (gInteractive) {
  287. #ifdef THINK_C
  288.                 if (isSelected) {
  289.                         gCurrentZoomCell.h = new_pos.x;
  290.                         gCurrentZoomCell.v = new_pos.y;
  291.                         gCurrentZoomItem = 0;
  292.  
  293.             GetPenState(&thePen);
  294.             SetRect(&r, START_X+gCurrentZoomCell.h*SQUARE_SIZE, START_Y+gCurrentZoomCell.v*SQUARE_SIZE, START_X+(gCurrentZoomCell.h+1)*SQUARE_SIZE - GAP_SIZE, START_Y+(gCurrentZoomCell.v+1)*SQUARE_SIZE-GAP_SIZE);
  295.             SetRect(&r, r.left-2, r.top-2,r.right+2, r.bottom+2);
  296.             FrameRect(&r);
  297.             SetPenState(&thePen);
  298.         }
  299. #endif
  300. #ifdef __MWERKS__
  301.                 if (isSelected) {
  302.                         gCurrentZoomCell.h = new_pos.x;
  303.                         gCurrentZoomCell.v = new_pos.y;
  304.                         gCurrentZoomItem = 0;
  305.  
  306.             GetPenState(&thePen);
  307.             SetRect(&r, START_X+gCurrentZoomCell.h*SQUARE_SIZE, START_Y+gCurrentZoomCell.v*SQUARE_SIZE, START_X+(gCurrentZoomCell.h+1)*SQUARE_SIZE - GAP_SIZE, START_Y+(gCurrentZoomCell.v+1)*SQUARE_SIZE-GAP_SIZE);
  308.             SetRect(&r, r.left-2, r.top-2,r.right+2, r.bottom+2);
  309.             FrameRect(&r);
  310.             SetPenState(&thePen);
  311.         }
  312. #endif
  313.  
  314.     }
  315. }
  316.